using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace EuropeEngulfed.NET
{
    partial class AlliedProductionDialog : Form
    {
        //4.43 COST TO BUILD CHART
        public const int SPECIAL_ACTION_PRICE = 5;
        public const int FLEET_PRICE = 10;
        public const int FLAK_PRICE = 10;
        public const int FIGHTER_PRICE = 3;
        public const int BOMBER_PRICE = 5;
        public const int ASW_PRICE = 15;

        public const int MAX_FRENCH_SPECIAL_ACTIONS = 1;
        public const int MAX_BRITISH_SPECIAL_ACTIONS = 2;

        public struct AlliedProductionDialogInfo
        {
            public int lendLeaseFromUSAToUSSR;
            public int UKloanToUSSR;
            public int UKSpecialActions;
            public bool UKFleetBuild;
            public bool UKFlakBuild;
            public bool UKASWBuild;
            public int UKFighters;
            public int UKbombers;
            public bool frenchFleetBuild;
            public int frenchSpecialActions;
            public bool USSRFleetBuild;
            public int USSRSpecialActions;
            public int USloanToUK;
            public int USSpecialActions;
            public bool USFleetBuild;
            public bool USASWBuild;
            public int USFighters;
            public int USbombers;
            public MapInfo.RegionID frenchFleetBuildRegion;
            public MapInfo.RegionID USSRFleetBuildRegion;
            public bool instituteRussianEmergency;
        };

        public AlliedProductionDialogInfo productionInfo;
        private int UKInitialWERPS;
        private int frenchInitialWERPS;
        private int USSRInitialWERPS;
        private int USAInitialWERPS;
        private int strategicWarfareLosses;
        private int UKFleetMaintenance;
        private int frenchFleetMaintenance;
        private int USSRFleetMaintenance;
        private int startingUKSpecialActions;
        private int startingFrenchSpecialActions;
        private int startingUSSRSpecialActions;
        private int maxUSSRSpecialActions;
        private int startingUSASpecialActions;
        private int maxUSASpecialActions;
        private bool UKFleetBuildAvailable;
        private bool frenchFleetBuildAvailable;
        private bool USAFleetBuildAvailable;
        private bool USSRFleetBuildAvailable;
        private bool FlakBuildable;
        private bool ASWBuildAvailable;
        private bool USAtWar;
        private bool USSRAtWar;
        private int lendLeaseFromUSAForUK;
        private int lendLeaseFromUSAForUSSR;
        private int UKNewUnitsAndReplacements = 0;
        private int frenchNewUnitsAndReplacements = 0;
        private int USSRNewUnitsAndReplacements = 0;
        private int USANewUnitsAndReplacements = 0;
        private int maxBritishWERPsToUSSR;
        private bool britishLendLeaseToUSSRHalved;
        private bool russiansCouldInsituteEmergencyConscription;
        private GameController.UKLendLease ukLendLease;

        public AlliedProductionDialog(int UKInitialWERPS, int frenchInitialWERPS, int USSRInitialWERPS, int USAInitialWERPS, int strategicWarfareLosses, int UKFleetMaintenance, int frenchFleetMaintenance, int USSRFleetMaintenance, int startingUKSpecialActions, int startingFrenchSpecialActions, int startingUSSRSpecialActions, int maxUSSRSpecialActions, int startingUSASpecialActions, int maxUSASpecialActions, bool UKFleetBuildAvailable, bool frenchFleetBuildAvailable, bool USAFleetBuildAvailable, bool USSRFleetBuildAvailable, bool FlakBuildable, bool ASWBuildAvailable, bool USAtWar, bool USSRAtWar, int lendLeaseFromUSAForUK, int lendLeaseFromUSAForUSSR, bool UKAtWar, int maxBritishWERPsToUSSR, bool britishLendLeaseToUSSRHalved, bool russiansCouldInsituteEmergencyConscription, bool russiansBlockedFromBuildingSA, GameController.UKLendLease ukLendLease)
        {
            InitializeComponent();

            this.ukLendLease = ukLendLease;
            this.UKInitialWERPS = UKInitialWERPS;
            this.frenchInitialWERPS = frenchInitialWERPS;
            this.USSRInitialWERPS = USSRInitialWERPS;
            this.USAInitialWERPS = USAInitialWERPS;
            this.strategicWarfareLosses = strategicWarfareLosses;
            this.UKFleetMaintenance = UKFleetMaintenance;
            this.frenchFleetMaintenance = frenchFleetMaintenance;
            this.USSRFleetMaintenance = USSRFleetMaintenance;
            this.startingUKSpecialActions = startingUKSpecialActions;
            this.startingFrenchSpecialActions = startingFrenchSpecialActions;
            this.startingUSSRSpecialActions = startingUSSRSpecialActions;
            this.maxUSSRSpecialActions = maxUSSRSpecialActions;
            this.startingUSASpecialActions = startingUSASpecialActions;
            this.maxUSASpecialActions = maxUSASpecialActions;
            this.UKFleetBuildAvailable = UKFleetBuildAvailable;
            this.frenchFleetBuildAvailable = frenchFleetBuildAvailable;
            this.USAFleetBuildAvailable = USAFleetBuildAvailable;
            this.USSRFleetBuildAvailable = USSRFleetBuildAvailable;
            this.FlakBuildable = FlakBuildable;
            this.ASWBuildAvailable = ASWBuildAvailable;
            this.USAtWar = USAtWar;
            this.USSRAtWar = USSRAtWar;
            this.lendLeaseFromUSAForUK = lendLeaseFromUSAForUK;
            this.lendLeaseFromUSAForUSSR = lendLeaseFromUSAForUSSR;
            this.maxBritishWERPsToUSSR = maxBritishWERPsToUSSR;
            this.britishLendLeaseToUSSRHalved = britishLendLeaseToUSSRHalved;
            this.russiansCouldInsituteEmergencyConscription = russiansCouldInsituteEmergencyConscription;

            productionInfo.lendLeaseFromUSAToUSSR = lendLeaseFromUSAForUSSR;
            productionInfo.UKloanToUSSR = 0;
            productionInfo.UKSpecialActions = 0;
            productionInfo.UKFleetBuild = false;
            productionInfo.UKFlakBuild = false;
            productionInfo.UKASWBuild = false;
            productionInfo.UKFighters = 0;
            productionInfo.UKbombers = 0;
            productionInfo.frenchFleetBuild = false;
            productionInfo.frenchSpecialActions = 0;
            productionInfo.USSRFleetBuild = false;
            productionInfo.USSRSpecialActions = 0;
            productionInfo.USloanToUK = lendLeaseFromUSAForUK;
            productionInfo.USSpecialActions = 0;
            productionInfo.USFleetBuild = false;
            productionInfo.USASWBuild = false;
            productionInfo.USFighters = 0;
            productionInfo.USbombers = 0;
            productionInfo.frenchFleetBuildRegion = MapInfo.RegionID.MediteraneanSea;
            productionInfo.USSRFleetBuildRegion = MapInfo.RegionID.BalticSea;
            productionInfo.instituteRussianEmergency = false;

            if (!UKAtWar)
            {
                UKProductionGroupBox.Enabled = false;
            }
            else
            {
                UKInitialWERPSAmountLabel.Text = UKInitialWERPS.ToString();
                UKFleetMaintenanceAmountLabel.Text = UKFleetMaintenance.ToString();
                strategicWarfareAmountLabel.Text = strategicWarfareLosses.ToString();
                if(!USSRAtWar)
                {
                    loanToUSSRLabel.Visible = false;
                    loanToUSSRhScrollBar.Visible = false;
                    amountLoanToUSSRLabel.Visible = false;
                }
                else
                {
                    loanToUSSRhScrollBar.Minimum = 0;
                    loanToUSSRhScrollBar.Maximum = Math.Min((UKInitialWERPS - strategicWarfareLosses + lendLeaseFromUSAForUK) / 2, maxBritishWERPsToUSSR);
                    if (britishLendLeaseToUSSRHalved)
                        loanToUSSRhScrollBar.SmallChange = 2;
                    if (ukLendLease == GameController.UKLendLease.Murmansk)
                        loanToUSSRInfoLabel.Text = "Through Murmansk";
                    else if(ukLendLease == GameController.UKLendLease.MurmanskHalved)
                        loanToUSSRInfoLabel.Text = "Through Murmansk(Halved)";
                    else if (ukLendLease == GameController.UKLendLease.Persia)
                        loanToUSSRInfoLabel.Text = "Through Persia";
                    loanToUSSRInfoLabel.Visible = true;
                }

                if(!USAtWar)
                {
                    USALoanLabel.Text = "USA Lend/Lease";
                    USLoanAmountLabel.Text = lendLeaseFromUSAForUK.ToString();
                }

                UKnumSpecialActions.Text = startingUKSpecialActions.ToString();
                UKspecialActionshScrollBar.Minimum = 0;
                UKspecialActionshScrollBar.Maximum = MAX_BRITISH_SPECIAL_ACTIONS - startingUKSpecialActions;
                UKFlakBuildCheckBox.Enabled = FlakBuildable;
                UKFleetBuildCheckBox.Enabled = UKFleetBuildAvailable;
                UKASWCheckBox.Enabled = ASWBuildAvailable;
            }

            if(frenchInitialWERPS  <= 0)
            {
                FrenchInitialWERPSAmountLabel.Text = "0";
                FrenchProductionGroupBox.Enabled = false;
            }
            else
            {
                FrenchInitialWERPSAmountLabel.Text = frenchInitialWERPS.ToString();
                FrenchFleetMaintenanceAmountLabel.Text = frenchFleetMaintenance.ToString();
                FrenchNumSpecialActions.Text = startingFrenchSpecialActions.ToString();
                FrenchSpecialActionshScrollBar.Minimum = 0;
                FrenchSpecialActionshScrollBar.Maximum = MAX_FRENCH_SPECIAL_ACTIONS - startingFrenchSpecialActions;
                FrenchFleetBuildCheckBox.Enabled = frenchFleetBuildAvailable;
            }

            if(USSRInitialWERPS <= 0)
            {
                USSRProductionGroupBox.Enabled = false;
                USSRInitialWERPSAmountLabel.Text = USSRInitialWERPS.ToString();
            }
            else
            {
                USSRInitialWERPSAmountLabel.Text = USSRInitialWERPS.ToString();
                USSRFleetMaintenanceAmountLabel.Text = USSRFleetMaintenance.ToString();
                if (!USAtWar)
                {
                    USALoanToUSSRLabel.Text = "USA Lend/Lease";
                    numUSALoanToUSSRLabel.Text = lendLeaseFromUSAForUSSR.ToString();
                }
                USSRNumSpecialActions.Text = startingUSSRSpecialActions.ToString();
                USSRSpecialActionshScrollBar.Minimum = 0;
                USSRSpecialActionshScrollBar.Maximum = maxUSSRSpecialActions - startingUSSRSpecialActions;
                if (russiansBlockedFromBuildingSA)
                    USSRSpecialActionshScrollBar.Enabled = false;
                if (!russiansCouldInsituteEmergencyConscription)
                    this.russianEmergencyPescriptionButton.Visible = false;
                USSRFleetBuildCheckBox.Enabled = USSRFleetBuildAvailable;
            }

            if(USAInitialWERPS <= 0)
            {
                USAInitialWERPSAmountLabel.Text = USAInitialWERPS.ToString();
                USAProductionGroupBox.Enabled = false;
            }
            else
            {
                USAInitialWERPSAmountLabel.Text = USAInitialWERPS.ToString();
                USAnumSpecialActions.Text = startingUSASpecialActions.ToString();
                USspecialActionshScrollBar.Minimum = 0;
                USspecialActionshScrollBar.Maximum = maxUSASpecialActions - startingUSASpecialActions;
                USAFleetBuildCheckBox.Enabled = USAFleetBuildAvailable;
                USAASWCheckBox.Enabled = ASWBuildAvailable;
            }

            this.nextPhaseButton.Visible = false;
            CalculateProductionValues();
        }

        public AlliedProductionDialog(int UKInitialWERPS, int frenchInitialWERPS, int USSRInitialWERPS, int USAInitialWERPS, int strategicWarfareLosses, int UKFleetMaintenance, int frenchFleetMaintenance, int USSRFleetMaintenance, int startingUKSpecialActions, int startingFrenchSpecialActions, int startingUSSRSpecialActions, int maxUSSRSpecialActions, int startingUSASpecialActions, int maxUSASpecialActions, bool UKFleetBuildAvailable, bool frenchFleetBuildAvailable, bool USAFleetBuildAvailable, bool USSRFleetBuildAvailable, bool FlakBuildable, bool ASWBuildAvailable, bool USAtWar, bool USSRAtWar, int lendLeaseFromUSAForUK, int lendLeaseFromUSAForUSSR, bool UKAtWar, int maxBritishWERPsToUSSR, bool britishLendLeaseToUSSRHalved, AlliedProductionDialogInfo productionInfo, int UKWERPsSpentOnNewUnitsReplacement, int frenchWERPsSpentOnNewUnitsReplacement, int USSRWERPsSpentOnNewUnitsReplacement, int USWERPsSpentOnNewUnitsReplacement, bool russiansCouldInsituteEmergencyConscription, bool russiansBlockedFromBuildingSA, GameController.UKLendLease ukLendLease)
            : this(UKInitialWERPS, frenchInitialWERPS, USSRInitialWERPS, USAInitialWERPS, strategicWarfareLosses, UKFleetMaintenance, frenchFleetMaintenance, USSRFleetMaintenance, startingUKSpecialActions, startingFrenchSpecialActions, startingUSSRSpecialActions, maxUSSRSpecialActions, startingUSASpecialActions, maxUSASpecialActions, UKFleetBuildAvailable, frenchFleetBuildAvailable, USAFleetBuildAvailable, USSRFleetBuildAvailable, FlakBuildable, ASWBuildAvailable, USAtWar, USSRAtWar, lendLeaseFromUSAForUK, lendLeaseFromUSAForUSSR, UKAtWar, maxBritishWERPsToUSSR, britishLendLeaseToUSSRHalved, russiansCouldInsituteEmergencyConscription, russiansBlockedFromBuildingSA, ukLendLease)
        {
            this.nextPhaseButton.Visible = true;
            this.productionInfo = productionInfo;
            this.UKNewUnitsAndReplacements = UKWERPsSpentOnNewUnitsReplacement;
            this.frenchNewUnitsAndReplacements = frenchWERPsSpentOnNewUnitsReplacement;
            this.USSRNewUnitsAndReplacements = USSRWERPsSpentOnNewUnitsReplacement;
            this.USANewUnitsAndReplacements = USWERPsSpentOnNewUnitsReplacement;
            loanToUSSRhScrollBar.Value = productionInfo.UKloanToUSSR;
            UKspecialActionshScrollBar.Value = productionInfo.UKSpecialActions;
            UKFlakBuildCheckBox.Checked = productionInfo.UKFlakBuild;
            UKFleetBuildCheckBox.Checked = productionInfo.UKFleetBuild;
            UKASWCheckBox.Checked = productionInfo.UKASWBuild;
            fighterhScrollBar.Value = productionInfo.UKFighters;
            UKBomberhScrollBar.Value = productionInfo.UKbombers;
            UKNewUnitsReplacementsAmountLabel.Text = UKWERPsSpentOnNewUnitsReplacement.ToString();
            FrenchSpecialActionshScrollBar.Value = productionInfo.frenchSpecialActions;
            FrenchFleetBuildCheckBox.Checked = productionInfo.frenchFleetBuild;
            FrenchNewUnitsReplacementsAmountLabel.Text = frenchWERPsSpentOnNewUnitsReplacement.ToString();
            loanToUKhScrollBar.Value = productionInfo.USloanToUK;
            USspecialActionshScrollBar.Value = productionInfo.USSpecialActions;
            USAFleetBuildCheckBox.Checked = productionInfo.USSRFleetBuild;
            USAASWCheckBox.Checked = productionInfo.USASWBuild;
            USfighterhScrollBar.Value = productionInfo.USFighters;
            USbomberhScrollBar.Value = productionInfo.USbombers;
            USANewUnitsReplacementsAmountLabel.Text = USANewUnitsAndReplacements.ToString();
            USSRSpecialActionshScrollBar.Value = productionInfo.USSRSpecialActions;
            USSRFleetBuildCheckBox.Checked = productionInfo.USSRFleetBuild;
            USSRNewUnitsReplacementsAmountLabel.Text = USSRNewUnitsAndReplacements.ToString();
            CalculateProductionValues();
        }

        private void CalculateProductionValues()
        {
            //UK
            amountLoanToUSSRLabel.Text = productionInfo.UKloanToUSSR.ToString();
            USLoanAmountLabel.Text = productionInfo.USloanToUK.ToString();
            UKnumSpecialActions.Text = (this.startingUKSpecialActions + productionInfo.UKSpecialActions).ToString();
            UKspecialActionsAmountLabel.Text = (productionInfo.UKSpecialActions * SPECIAL_ACTION_PRICE).ToString();
            UKFlakBuildAmountLabel.Text = productionInfo.UKFlakBuild ? FLAK_PRICE.ToString() : "0";
            UKfleetBuildAmountLabel.Text = productionInfo.UKFleetBuild ? FLEET_PRICE.ToString() : "0";
            UKASWAmountLabel.Text = productionInfo.UKASWBuild ? ASW_PRICE.ToString() : "0";
            UKfighterBuildAmountLabel.Text = (productionInfo.UKFighters * FIGHTER_PRICE).ToString();
            UKnumFighterLabel.Text = productionInfo.UKFighters.ToString();
            UKbomberBuildAmountLabel.Text = (productionInfo.UKbombers * BOMBER_PRICE).ToString();
            UKnumBomberLabel.Text = productionInfo.UKbombers.ToString();
            int UKRemainingWERPS = this.UKInitialWERPS - strategicWarfareLosses - UKFleetMaintenance + productionInfo.USloanToUK - productionInfo.UKloanToUSSR
            - (productionInfo.UKSpecialActions * SPECIAL_ACTION_PRICE) - (productionInfo.UKFighters * FIGHTER_PRICE) - (productionInfo.UKbombers * BOMBER_PRICE)
            - UKNewUnitsAndReplacements;
            if (productionInfo.UKFleetBuild)
                UKRemainingWERPS -= FLEET_PRICE;
            if (productionInfo.UKFlakBuild)
                UKRemainingWERPS -= FLAK_PRICE;
            if (productionInfo.UKASWBuild)
                UKRemainingWERPS -= ASW_PRICE;
            UKNumWERPSLeftLabel.Text = UKRemainingWERPS.ToString();

            //France
            FrenchNumSpecialActions.Text = (this.startingFrenchSpecialActions + productionInfo.frenchSpecialActions).ToString();
            FrenchSpecialActionsAmountLabel.Text = (productionInfo.frenchSpecialActions * SPECIAL_ACTION_PRICE).ToString();
            FrenchFleetBuildAmountLabel.Text = productionInfo.frenchFleetBuild ? FLEET_PRICE.ToString() : "0";
            int frenchRemainingWERPS = this.frenchInitialWERPS - frenchFleetMaintenance - (productionInfo.frenchSpecialActions * SPECIAL_ACTION_PRICE) - frenchNewUnitsAndReplacements;
            if(productionInfo.frenchFleetBuild)
                frenchRemainingWERPS -= FLEET_PRICE;
            FrenchNumWERPSLeftLabel.Text = frenchRemainingWERPS.ToString();
            //USSR
            numUSALoanToUSSRLabel.Text = productionInfo.lendLeaseFromUSAToUSSR.ToString();
            USSRNumSpecialActions.Text = (this.startingUSSRSpecialActions + productionInfo.USSRSpecialActions).ToString();
            USSRSpecialActionsAmountLabel.Text = (productionInfo.USSRSpecialActions * SPECIAL_ACTION_PRICE).ToString();
            USSRFleetBuildAmountLabel.Text = productionInfo.USSRFleetBuild ? FLEET_PRICE.ToString() : "0";
            int USSRRemainingWERPS = this.USSRInitialWERPS - USSRFleetMaintenance + productionInfo.lendLeaseFromUSAToUSSR - (productionInfo.USSRSpecialActions * SPECIAL_ACTION_PRICE)
            - USSRNewUnitsAndReplacements;
            if(productionInfo.USSRFleetBuild)
                USSRRemainingWERPS -= FLEET_PRICE;
            if (britishLendLeaseToUSSRHalved)
            {
                numUKLoanLabel.Text = (productionInfo.UKloanToUSSR / 2).ToString();
                USSRRemainingWERPS += (productionInfo.UKloanToUSSR / 2);
            }
            else
            {
                numUKLoanLabel.Text = productionInfo.UKloanToUSSR.ToString();
                USSRRemainingWERPS += productionInfo.UKloanToUSSR;
            }

            USSRNumWERPSLeftLabel.Text = USSRRemainingWERPS.ToString();
            //USA
            amountLoanToUKLabel.Text = productionInfo.USloanToUK.ToString();
            USAnumSpecialActions.Text = (this.startingUSASpecialActions + productionInfo.USSpecialActions).ToString();
            USAspecialActionsAmountLabel.Text = (productionInfo.USSpecialActions * SPECIAL_ACTION_PRICE).ToString();
            USAfleetBuildAmountLabel.Text = productionInfo.USFleetBuild ? FLEET_PRICE.ToString() : "0";
            USAASWAmountLabel.Text = productionInfo.USASWBuild ? ASW_PRICE.ToString() : "0";
            USAnumFighterLabel.Text = productionInfo.USFighters.ToString();
            USAfighterBuildAmountLabel.Text = (productionInfo.USFighters * FIGHTER_PRICE).ToString();
            USAnumBomberLabel.Text = productionInfo.USbombers.ToString();
            USAbomberBuildAmountLabel.Text = (productionInfo.USbombers * BOMBER_PRICE).ToString();
            int USARemainingWERPS = this.USAInitialWERPS - productionInfo.USloanToUK - (productionInfo.USSpecialActions * SPECIAL_ACTION_PRICE)
            - (productionInfo.USFighters * FIGHTER_PRICE) - (productionInfo.USbombers * BOMBER_PRICE)
            - USANewUnitsAndReplacements;
            if (productionInfo.USASWBuild)
                USARemainingWERPS -= ASW_PRICE;
            if (productionInfo.USFleetBuild)
                USARemainingWERPS -= FLEET_PRICE;
            USANumWERPSLeftLabel.Text = USARemainingWERPS.ToString();
        }

        private void OkButton_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void UKProductionGroupBox_Paint(object sender, PaintEventArgs e)
        {
            Bitmap bitmapToDraw;

            PlayingPieceGraphics.PaintControlMarker(e.Graphics, MapInfo.CountryID.GreatBritain, new Point(50, 50), false);
            e.Graphics.DrawLine(Pens.Black, new Point(60, 335), new Point(400, 335));
            bitmapToDraw = EEGraphics.TransparentBritishSAs;
            e.Graphics.DrawImage(bitmapToDraw, this.UKnumSpecialActions.Location.X - (int)(((float)this.UKnumSpecialActions.Height / (float)bitmapToDraw.Height) * (float)bitmapToDraw.Width), this.UKnumSpecialActions.Location.Y, (int)(((float)this.UKnumSpecialActions.Height / (float)bitmapToDraw.Height) * (float)bitmapToDraw.Width), this.UKnumSpecialActions.Height);
            bitmapToDraw = EEGraphics.BritishFlakPoints;
            e.Graphics.DrawImage(bitmapToDraw, this.UKFlakBuildLabel.Location.X - (int)(((float)this.UKFlakBuildLabel.Height / (float)bitmapToDraw.Height) * (float)bitmapToDraw.Width), this.UKFlakBuildLabel.Location.Y, (int)(((float)this.UKFlakBuildLabel.Height / (float)bitmapToDraw.Height) * (float)bitmapToDraw.Width), this.UKFlakBuildLabel.Height);
            bitmapToDraw = EEGraphics.USBritishFleetPoint;
            e.Graphics.DrawImage(bitmapToDraw, this.UKFleetBuildLabel.Location.X - (int)(((float)this.UKFleetBuildLabel.Height / (float)bitmapToDraw.Height) * (float)bitmapToDraw.Width), this.UKFleetBuildLabel.Location.Y, (int)(((float)this.UKFleetBuildLabel.Height / (float)bitmapToDraw.Height) * (float)bitmapToDraw.Width), this.UKFleetBuildLabel.Height);
            bitmapToDraw = EEGraphics.BritishASWLevel;
            e.Graphics.DrawImage(bitmapToDraw, this.UKASWLabel.Location.X - (int)(((float)this.UKASWLabel.Height / (float)bitmapToDraw.Height) * (float)bitmapToDraw.Width), this.UKASWLabel.Location.Y, (int)(((float)this.UKASWLabel.Height / (float)bitmapToDraw.Height) * (float)bitmapToDraw.Width), this.UKASWLabel.Height);
            bitmapToDraw = EEGraphics.WesternAlliedFighterPoints;
            e.Graphics.DrawImage(bitmapToDraw, this.UKnumFighterLabel.Location.X - (int)(((float)this.UKnumFighterLabel.Height / (float)bitmapToDraw.Height) * (float)bitmapToDraw.Width), this.UKnumFighterLabel.Location.Y, (int)(((float)this.UKnumFighterLabel.Height / (float)bitmapToDraw.Height) * (float)bitmapToDraw.Width), this.UKnumFighterLabel.Height);
            bitmapToDraw = EEGraphics.WesternAlliedBomberPoints;
            e.Graphics.DrawImage(bitmapToDraw, this.UKnumBomberLabel.Location.X - (int)(((float)this.UKnumBomberLabel.Height / (float)bitmapToDraw.Height) * (float)bitmapToDraw.Width), this.UKnumBomberLabel.Location.Y, (int)(((float)this.UKnumBomberLabel.Height / (float)bitmapToDraw.Height) * (float)bitmapToDraw.Width), this.UKnumBomberLabel.Height);
        }

        private void USAProductionGroupBox_Paint(object sender, PaintEventArgs e)
        {
            Bitmap bitmapToDraw;

            PlayingPieceGraphics.PaintControlMarker(e.Graphics, MapInfo.CountryID.USA, new Point(50, 50), false);
            e.Graphics.DrawLine(Pens.Black, new Point(50, 260), new Point(395, 260));
            bitmapToDraw = EEGraphics.TransparentUSControlSAs;
            e.Graphics.DrawImage(bitmapToDraw, this.USAnumSpecialActions.Location.X - (int)(((float)this.USAnumSpecialActions.Height / (float)bitmapToDraw.Height) * (float)bitmapToDraw.Width), this.USAnumSpecialActions.Location.Y, (int)(((float)this.USAnumSpecialActions.Height / (float)bitmapToDraw.Height) * (float)bitmapToDraw.Width), this.USAnumSpecialActions.Height);
            bitmapToDraw = EEGraphics.USBritishFleetPoint;
            e.Graphics.DrawImage(bitmapToDraw, this.USAFleetBuildLabel.Location.X - (int)(((float)this.USAFleetBuildLabel.Height / (float)bitmapToDraw.Height) * (float)bitmapToDraw.Width), this.USAFleetBuildLabel.Location.Y, (int)(((float)this.USAFleetBuildLabel.Height / (float)bitmapToDraw.Height) * (float)bitmapToDraw.Width), this.USAFleetBuildLabel.Height);
            bitmapToDraw = EEGraphics.BritishASWLevel;
            e.Graphics.DrawImage(bitmapToDraw, this.USAASWLabel.Location.X - (int)(((float)this.USAASWLabel.Height / (float)bitmapToDraw.Height) * (float)bitmapToDraw.Width), this.USAASWLabel.Location.Y, (int)(((float)this.USAASWLabel.Height / (float)bitmapToDraw.Height) * (float)bitmapToDraw.Width), this.USAASWLabel.Height);
            bitmapToDraw = EEGraphics.WesternAlliedFighterPoints;
            e.Graphics.DrawImage(bitmapToDraw, this.USAnumFighterLabel.Location.X - (int)(((float)this.USAnumFighterLabel.Height / (float)bitmapToDraw.Height) * (float)bitmapToDraw.Width), this.USAnumFighterLabel.Location.Y, (int)(((float)this.USAnumFighterLabel.Height / (float)bitmapToDraw.Height) * (float)bitmapToDraw.Width), this.USAnumFighterLabel.Height);
            bitmapToDraw = EEGraphics.WesternAlliedBomberPoints;
            e.Graphics.DrawImage(bitmapToDraw, this.USAnumBomberLabel.Location.X - (int)(((float)this.USAnumBomberLabel.Height / (float)bitmapToDraw.Height) * (float)bitmapToDraw.Width), this.USAnumBomberLabel.Location.Y, (int)(((float)this.USAnumBomberLabel.Height / (float)bitmapToDraw.Height) * (float)bitmapToDraw.Width), this.USAnumBomberLabel.Height);
        }

        private void FrenchProductionGroupBox_Paint(object sender, PaintEventArgs e)
        {
            Bitmap bitmapToDraw;

            PlayingPieceGraphics.PaintControlMarker(e.Graphics, MapInfo.CountryID.France, new Point(30, 35), false);
            e.Graphics.DrawLine(Pens.Black, new Point(60, 150), new Point(400, 150));
            bitmapToDraw = EEGraphics.TransparentFrenchControlSAs;
            e.Graphics.DrawImage(bitmapToDraw, this.FrenchNumSpecialActions.Location.X - (int)(((float)this.FrenchNumSpecialActions.Height / (float)bitmapToDraw.Height) * (float)bitmapToDraw.Width), this.FrenchNumSpecialActions.Location.Y, (int)(((float)this.FrenchNumSpecialActions.Height / (float)bitmapToDraw.Height) * (float)bitmapToDraw.Width), this.FrenchNumSpecialActions.Height);
            bitmapToDraw = EEGraphics.FrenchFleetPoint;
            e.Graphics.DrawImage(bitmapToDraw, this.FrenchFleetBuildLabel.Location.X - (int)(((float)this.FrenchFleetBuildLabel.Height / (float)bitmapToDraw.Height) * (float)bitmapToDraw.Width), this.FrenchFleetBuildLabel.Location.Y, (int)(((float)this.FrenchFleetBuildLabel.Height / (float)bitmapToDraw.Height) * (float)bitmapToDraw.Width), this.FrenchFleetBuildLabel.Height);
        }

        private void USSRProductionGroupBox_Paint(object sender, PaintEventArgs e)
        {
            Bitmap bitmapToDraw;

            PlayingPieceGraphics.PaintControlMarker(e.Graphics, MapInfo.CountryID.USSR, new Point(50, 50), false);
            e.Graphics.DrawLine(Pens.Black, new Point(50, 200), new Point(395, 200));
            bitmapToDraw = EEGraphics.TransparentSovietControlSAs;
            e.Graphics.DrawImage(bitmapToDraw, this.USSRNumSpecialActions.Location.X - (int)(((float)this.USSRNumSpecialActions.Height / (float)bitmapToDraw.Height) * (float)bitmapToDraw.Width), this.USSRNumSpecialActions.Location.Y, (int)(((float)this.USSRNumSpecialActions.Height / (float)bitmapToDraw.Height) * (float)bitmapToDraw.Width), this.USSRNumSpecialActions.Height);
            bitmapToDraw = EEGraphics.SovietFleetPoint;
            e.Graphics.DrawImage(bitmapToDraw, this.USSRFleetBuildLabel.Location.X - (int)(((float)this.USSRFleetBuildLabel.Height / (float)bitmapToDraw.Height) * (float)bitmapToDraw.Width), this.USSRFleetBuildLabel.Location.Y, (int)(((float)this.USSRFleetBuildLabel.Height / (float)bitmapToDraw.Height) * (float)bitmapToDraw.Width), this.USSRFleetBuildLabel.Height);
        }

        private void loanToUSSRhScrollBar_ValueChanged(object sender, EventArgs e)
        {
            int previousValue = this.productionInfo.UKloanToUSSR;
            this.productionInfo.UKloanToUSSR = loanToUSSRhScrollBar.Value;
            CalculateProductionValues();
            if (Int32.Parse(this.UKNumWERPSLeftLabel.Text) < 0 || Int32.Parse(this.USSRNumWERPSLeftLabel.Text) < 0)
            {
                this.productionInfo.UKloanToUSSR = previousValue;
                loanToUSSRhScrollBar.Value = this.productionInfo.UKloanToUSSR;
                CalculateProductionValues();
            }
        }

        private void UKspecialActionshScrollBar_ValueChanged(object sender, EventArgs e)
        {
            int previousValue = this.productionInfo.UKSpecialActions;
            this.productionInfo.UKSpecialActions = UKspecialActionshScrollBar.Value;
            CalculateProductionValues();
            if (Int32.Parse(this.UKNumWERPSLeftLabel.Text) < 0)
            {
                this.productionInfo.UKSpecialActions = previousValue;
                UKspecialActionshScrollBar.Value = this.productionInfo.UKSpecialActions;
                CalculateProductionValues();
            }
        }

        private void UKFlakBuildCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            this.productionInfo.UKFlakBuild = this.UKFlakBuildCheckBox.Checked;
            CalculateProductionValues();
            if (this.UKFlakBuildCheckBox.Checked)
            {
                if (Int32.Parse(this.UKNumWERPSLeftLabel.Text) < 0)
                {
                    this.UKFlakBuildCheckBox.Checked = false;
                    this.productionInfo.UKFlakBuild = false;
                    CalculateProductionValues();
                }
            }
        }

        private void UKFleetBuildCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            this.productionInfo.UKFleetBuild = this.UKFleetBuildCheckBox.Checked;
            CalculateProductionValues();
            if (this.UKFleetBuildCheckBox.Checked)
            {
                if (Int32.Parse(this.UKNumWERPSLeftLabel.Text) < 0)
                {
                    this.UKFleetBuildCheckBox.Checked = false;
                    this.productionInfo.UKFleetBuild = false;
                    CalculateProductionValues();
                }
            }
        }

        private void UKASWCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            if (this.productionInfo.USASWBuild)
            {
                this.UKASWCheckBox.Checked = false;
                CalculateProductionValues();
            }
            else
            {
                this.productionInfo.UKASWBuild = this.UKASWCheckBox.Checked;
                CalculateProductionValues();
                if (this.UKASWCheckBox.Checked)
                {
                    if (Int32.Parse(this.UKNumWERPSLeftLabel.Text) < 0)
                    {
                        this.UKASWCheckBox.Checked = false;
                        this.productionInfo.UKASWBuild = false;
                        CalculateProductionValues();
                    }
                }
            }
        }

        private void fighterhScrollBar_ValueChanged(object sender, EventArgs e)
        {
            int previousValue = this.productionInfo.UKFighters;
            this.productionInfo.UKFighters = fighterhScrollBar.Value;
            CalculateProductionValues();
            if (Int32.Parse(this.UKNumWERPSLeftLabel.Text) < 0 || (this.productionInfo.UKFighters + this.productionInfo.UKbombers) > ProductionMove.MAX_NUM_BRITISH_AIRCRAFT_POINTS)
            {
                this.productionInfo.UKFighters = previousValue;
                fighterhScrollBar.Value = this.productionInfo.UKFighters;
                CalculateProductionValues();
            }
        }

        private void UKBomberhScrollBar_ValueChanged(object sender, EventArgs e)
        {
            int previousValue = this.productionInfo.UKbombers;
            this.productionInfo.UKbombers = UKBomberhScrollBar.Value;
            CalculateProductionValues();
            if (Int32.Parse(this.UKNumWERPSLeftLabel.Text) < 0 || (this.productionInfo.UKFighters + this.productionInfo.UKbombers) > ProductionMove.MAX_NUM_BRITISH_AIRCRAFT_POINTS)
            {
                this.productionInfo.UKbombers = previousValue;
                UKBomberhScrollBar.Value = this.productionInfo.UKbombers;
                CalculateProductionValues();
            }
        }

        private void FrenchSpecialActionshScrollBar_ValueChanged(object sender, EventArgs e)
        {
            int previousValue = this.productionInfo.frenchSpecialActions;
            this.productionInfo.frenchSpecialActions = FrenchSpecialActionshScrollBar.Value;
            CalculateProductionValues();
            if (Int32.Parse(this.FrenchNumWERPSLeftLabel.Text) < 0)
            {
                this.productionInfo.frenchSpecialActions = previousValue;
                FrenchSpecialActionshScrollBar.Value = this.productionInfo.frenchSpecialActions;
                CalculateProductionValues();
            }
        }

        private void FrenchFleetBuildCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            this.productionInfo.frenchFleetBuild = this.FrenchFleetBuildCheckBox.Checked;
            CalculateProductionValues();
            if (this.FrenchFleetBuildCheckBox.Checked)
            {
                List<MapInfo.RegionID> listOfSeaRegions = new List<MapInfo.RegionID>();

                listOfSeaRegions.Add(MapInfo.RegionID.AtlanticOcean);
                listOfSeaRegions.Add(MapInfo.RegionID.MediteraneanSea);
                RegionSelectionDialog regionSelectDialog = new RegionSelectionDialog(listOfSeaRegions, "What region do you want build the new french fleet?");
                regionSelectDialog.ShowDialog();

                if (Int32.Parse(this.FrenchNumWERPSLeftLabel.Text) < 0 || regionSelectDialog.DialogResult != DialogResult.OK)
                {
                    this.FrenchFleetBuildCheckBox.Checked = false;
                    this.productionInfo.frenchFleetBuild = false;
                    CalculateProductionValues();
                }
                else
                    productionInfo.frenchFleetBuildRegion = regionSelectDialog.SelectedRegion;
            }
        }

        private void loanToUKhScrollBar_ValueChanged(object sender, EventArgs e)
        {
            int previousValue = this.productionInfo.USloanToUK;
            this.productionInfo.USloanToUK = loanToUKhScrollBar.Value;
            CalculateProductionValues();
            if (Int32.Parse(this.UKNumWERPSLeftLabel.Text) < 0 || Int32.Parse(this.USANumWERPSLeftLabel.Text) < 0)
            {
                this.productionInfo.USloanToUK = previousValue;
                loanToUKhScrollBar.Value = this.productionInfo.USloanToUK;
                CalculateProductionValues();
            }
        }

        private void USspecialActionshScrollBar_ValueChanged(object sender, EventArgs e)
        {
            int previousValue = this.productionInfo.USSpecialActions;
            this.productionInfo.USSpecialActions = USspecialActionshScrollBar.Value;
            CalculateProductionValues();
            if (Int32.Parse(this.USANumWERPSLeftLabel.Text) < 0)
            {
                this.productionInfo.USSpecialActions = previousValue;
                USspecialActionshScrollBar.Value = this.productionInfo.USSpecialActions;
                CalculateProductionValues();
            }
        }

        private void USAFleetBuildCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            this.productionInfo.USFleetBuild = this.USAFleetBuildCheckBox.Checked;
            CalculateProductionValues();
            if (this.USAFleetBuildCheckBox.Checked)
            {
                if (Int32.Parse(this.USANumWERPSLeftLabel.Text) < 0)
                {
                    this.USAFleetBuildCheckBox.Checked = false;
                    this.productionInfo.USFleetBuild = false;
                    CalculateProductionValues();
                }
            }
        }

        private void USAASWCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            if (this.productionInfo.UKASWBuild)
            {
                this.USAASWCheckBox.Checked = false;
                CalculateProductionValues();
            }
            else
            {
                this.productionInfo.USASWBuild = this.USAASWCheckBox.Checked;
                CalculateProductionValues();
                if (this.USAASWCheckBox.Checked)
                {
                    if (Int32.Parse(this.USANumWERPSLeftLabel.Text) < 0)
                    {
                        this.USAASWCheckBox.Checked = false;
                        this.productionInfo.USASWBuild = false;
                        CalculateProductionValues();
                    }
                }
            }
        }

        private void USfighterhScrollBar_ValueChanged(object sender, EventArgs e)
        {
            int previousValue = this.productionInfo.USFighters;
            this.productionInfo.USFighters = USfighterhScrollBar.Value;
            CalculateProductionValues();
            if (Int32.Parse(this.USANumWERPSLeftLabel.Text) < 0 || (this.productionInfo.USFighters + this.productionInfo.USbombers) > ProductionMove.MAX_NUM_US_AIRCRAFT_POINTS)
            {
                this.productionInfo.USFighters = previousValue;
                USfighterhScrollBar.Value = this.productionInfo.USFighters;
                CalculateProductionValues();
            }
        }

        private void USbomberhScrollBar_ValueChanged(object sender, EventArgs e)
        {
            int previousValue = this.productionInfo.USbombers;
            this.productionInfo.USbombers = USbomberhScrollBar.Value;
            CalculateProductionValues();
            if (Int32.Parse(this.USANumWERPSLeftLabel.Text) < 0 || (this.productionInfo.USFighters + this.productionInfo.USbombers) > ProductionMove.MAX_NUM_US_AIRCRAFT_POINTS)
            {
                this.productionInfo.USbombers = previousValue;
                USbomberhScrollBar.Value = this.productionInfo.USbombers;
                CalculateProductionValues();
            }
        }

        private void USSRSpecialActionshScrollBar_ValueChanged(object sender, EventArgs e)
        {
            int previousValue = this.productionInfo.USSRSpecialActions;
            this.productionInfo.USSRSpecialActions = USSRSpecialActionshScrollBar.Value;
            CalculateProductionValues();
            if (Int32.Parse(this.USSRNumWERPSLeftLabel.Text) < 0)
            {
                this.productionInfo.USSRSpecialActions = previousValue;
                USSRSpecialActionshScrollBar.Value = this.productionInfo.USSRSpecialActions;
                CalculateProductionValues();
            }
            if (USSRSpecialActionshScrollBar.Value > 0)
                this.russianEmergencyPescriptionButton.Enabled = false;
            else if (russiansCouldInsituteEmergencyConscription)
                this.russianEmergencyPescriptionButton.Enabled = true;
        }

        private void USSRFleetBuildCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            this.productionInfo.USSRFleetBuild = this.USSRFleetBuildCheckBox.Checked;
            CalculateProductionValues();
            if (this.USSRFleetBuildCheckBox.Checked)
            {
                List<MapInfo.RegionID> listOfSeaRegions = new List<MapInfo.RegionID>();

                listOfSeaRegions.Add(MapInfo.RegionID.BalticSea);
                listOfSeaRegions.Add(MapInfo.RegionID.BlackSea);
                RegionSelectionDialog regionSelectDialog = new RegionSelectionDialog(listOfSeaRegions, "What region do you want build the new USSR fleet?");
                regionSelectDialog.ShowDialog();

                if (Int32.Parse(this.USSRNumWERPSLeftLabel.Text) < 0)
                {
                    this.USSRFleetBuildCheckBox.Checked = false;
                    this.productionInfo.USSRFleetBuild = false;
                    CalculateProductionValues();
                }
                else
                    productionInfo.USSRFleetBuildRegion = regionSelectDialog.SelectedRegion;
            }
        }

        private void nextPhaseButton_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Yes;
            this.Close();
        }

        private void russianEmergencyPescriptionButton_Click(object sender, EventArgs e)
        {
            if(MessageBox.Show(this,"Are you sure you want to activate Russian Emergency Conscription?", "Emergency Conscription", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                USSRSpecialActionshScrollBar.Enabled = false;
                russianEmergencyPescriptionButton.Enabled = false;
                this.productionInfo.instituteRussianEmergency = true;
            }
        }
    }
}